From 32060bbf972ed0de3c7bf3b862568214574398ab Mon Sep 17 00:00:00 2001 From: "kaf24@firebug.cl.cam.ac.uk" Date: Sat, 6 Aug 2005 09:48:47 +0000 Subject: [PATCH] This patch changes the shutdown driver and xend to use strings instead of codes for signaling a shutdown request. Also, we fix the return code for the shutdown notifier, so other notifiers will get to run ;) Signed-off-by: Dan Smith --- linux-2.6-xen-sparse/arch/xen/kernel/reboot.c | 36 ++++++++++++------- tools/python/xen/xend/XendDomainInfo.py | 13 ++----- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/linux-2.6-xen-sparse/arch/xen/kernel/reboot.c b/linux-2.6-xen-sparse/arch/xen/kernel/reboot.c index ecb547302e..7a19712c47 100644 --- a/linux-2.6-xen-sparse/arch/xen/kernel/reboot.c +++ b/linux-2.6-xen-sparse/arch/xen/kernel/reboot.c @@ -247,19 +247,31 @@ static void shutdown_handler(struct xenbus_watch *watch, const char *node) { static DECLARE_WORK(shutdown_work, __shutdown_handler, NULL); - int type = -1; + char *str; + unsigned int len; - if (!xenbus_scanf("control", "shutdown", "%i", &type)) { - printk("Unable to read code in control/shutdown\n"); + str = (char *)xenbus_read("control", "shutdown", &len); + + if (! len) { return; - }; + } xenbus_printf("control", "shutdown", "%i", SHUTDOWN_INVALID); - if ((type == SHUTDOWN_POWEROFF) || - (type == SHUTDOWN_REBOOT) || - (type == SHUTDOWN_SUSPEND)) { - shutting_down = type; + if (strncmp(str, "poweroff", len) == 0) { + shutting_down = SHUTDOWN_POWEROFF; + } else if (strncmp(str, "reboot", len) == 0) { + shutting_down = SHUTDOWN_REBOOT; + } else if (strncmp(str, "suspend", len) == 0) { + shutting_down = SHUTDOWN_SUSPEND; + } else { + printk("Ignoring shutdown request: %s\n", str); + shutting_down = SHUTDOWN_INVALID; + } + + kfree(str); + + if (shutting_down != SHUTDOWN_INVALID) { schedule_work(&shutdown_work); } @@ -271,7 +283,7 @@ static void sysrq_handler(struct xenbus_watch *watch, const char *node) char sysrq_key = '\0'; if (!xenbus_scanf("control", "sysrq", "%c", &sysrq_key)) { - printk("Unable to read sysrq code in control/sysrq\n"); + printk(KERN_ERR "Unable to read sysrq code in control/sysrq\n"); return; } @@ -319,16 +331,16 @@ static int setup_shutdown_watcher(struct notifier_block *notifier, up(&xenbus_lock); if (err1) { - printk("Failed to set shutdown watcher\n"); + printk(KERN_ERR "Failed to set shutdown watcher\n"); } #ifdef CONFIG_MAGIC_SYSRQ if (err2) { - printk("Failed to set sysrq watcher\n"); + printk(KERN_ERR "Failed to set sysrq watcher\n"); } #endif - return NOTIFY_STOP; + return NOTIFY_DONE; } static int __init setup_shutdown_event(void) diff --git a/tools/python/xen/xend/XendDomainInfo.py b/tools/python/xen/xend/XendDomainInfo.py index 3510f79441..968ab2d444 100644 --- a/tools/python/xen/xend/XendDomainInfo.py +++ b/tools/python/xen/xend/XendDomainInfo.py @@ -52,14 +52,6 @@ shutdown_reasons = { DOMAIN_CRASH : "crash", } -"""Map shutdown reasons to codes -""" -shutdown_codes = { - 'poweroff' : DOMAIN_POWEROFF, - 'reboot' : DOMAIN_REBOOT, - 'suspend' : DOMAIN_SUSPEND, - } - RESTART_ALWAYS = 'always' RESTART_ONREBOOT = 'onreboot' RESTART_NEVER = 'never' @@ -939,11 +931,10 @@ class XendDomainInfo: self.channel.writeRequest(msg) def shutdown(self, reason): - reasonid = shutdown_codes.get(reason) - if reasonid == None: + if not reason in shutdown_reasons.values(): raise XendError('invalid reason:' + reason) db = self.db.addChild("/control"); - db['shutdown'] = '%i' % reasonid; + db['shutdown'] = reason; db.saveDB(save=True); if not reason in ['suspend']: self.shutdown_pending = {'start':time.time(), 'reason':reason} -- 2.30.2